//--线条 //3-----点击文字特效---

1,定义JSON结构

 

 

 2,调用类生成JSON格式

FC_JSON = /UI2/CL_JSON=>SERIALIZEDATA LS_JSON PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-LOW_CASE ASSOC_ARRAYS = ABAP_TRUE ASSOC_ARRAYS_OPT = ABAP_TRUE ).

 

 3,调用生成 CALCULATE_HASH_FOR_CHAR 生成加密签名

 

 4,创建http 对象

CL_HTTP_CLIENT=>CREATE_BY_URL

  1  DATA: LF_TIMESTAMPL_B TYPE TIMESTAMPL,
  2         LF_TIMESTAMPL_E TYPE TIMESTAMPL.
  3   DATA: LT_ALV TYPE TT_ALV,
  4         LS_ALV TYPE TY_ALV.
  5   DATA: LS_JSON TYPE STRING .
  6 
  7   CLEAR: LT_ALV ,LT_ALV[] .
  8   LOOP AT GT_ALV INTO GS_ALV WHERE CHECK = 'X' OR CHECKBOX = 'X' .
  9     APPEND GS_ALV TO LT_ALV .
 10     CLEAR GS_ALV .
 11   ENDLOOP .
 12   CHECK LT_ALV[] IS NOT INITIAL .
 13 
 14 
 15   DATA: LT_ZTMT014ERR TYPE TABLE OF ZTMT014ERR,
 16         LS_ZTMT014ERR TYPE ZTMT014ERR.
 17   DATA: LT_ZTMT014 TYPE TABLE OF ZTMT014,
 18         LS_ZTMT014 TYPE ZTMT014.
 19 
 20   DATA LF_LOGSYS TYPE T000-LOGSYS .
 21   CLEAR LF_LOGSYS .
 22   SELECT SINGLE LOGSYS INTO LF_LOGSYS FROM T000 WHERE MANDT = SY-MANDT .
 23   LOOP AT GT_ALV INTO GS_ALV WHERE CHECK = 'X' OR CHECKBOX = 'X'  .
 24 
 25     CLEAR: LT_ZTMT014 ,LT_ZTMT014[] .
 26     CLEAR: LT_ZTMT014ERR ,LT_ZTMT014ERR[] .
 27 
 28     CLEAR LS_JSON .
 29     PERFORM FRM_GET_TOR_DATA USING GS_ALV-TOR_ROOT_KEY CHANGING LS_JSON .
 30 * 执行url
 31 
 32     DATA: LF_TIMESTAMP TYPE CEST1-TIMESTMP,
 33           LF_SECRETKEY TYPE STRING,
 34           LF_SECRET    TYPE STRING,
 35           LF_DATA      TYPE STRING,
 36           LF_SIGN      TYPE STRING.
 37     DATA: LF_BASE_URL TYPE STRING VALUE 'http://ziyan.hzmmys.com/restapi/',
 38           LF_JIEKOU   TYPE STRING VALUE 'tms/open/gateway/api.order.create'.
 39     IF LF_LOGSYS = 'S4PCLN100'.
 40       LF_BASE_URL = 'http://tmmp.foods.com/restapi/' .
 41     ELSE .
 42       LF_BASE_URL = 'http://zytmq.zfoods.com/restapi/' .
 43     ENDIF.
 44 
 45 
 46 
 47     DATA: LF_REL_DATE            LIKE SY-DATUM  VALUE '19700101', " Bezugsdatum
 48           LF_SECONDS_PER_DAY(8)  TYPE P         VALUE 86400,
 49           LF_SECONDS_PER_HOUR(8) TYPE P         VALUE 3600.
 50     DATA: LF_DAYS TYPE INT4 .
 51     LF_DAYS = SY-DATUM - LF_REL_DATE .
 52     LF_TIMESTAMP = LF_DAYS * LF_SECONDS_PER_DAY + SY-UZEIT - SY-TZONE.
 53     LF_SECRETKEY = 'ziyan-tm' .
 54     LF_SECRET = 'ziyan-tm-qwueiqoweuqw' .
 55 
 56 
 57 *      DATA LF_LEN_VISUAL TYPE I .
 58 *      CALL FUNCTION 'NLS_VISUAL_CHARLEN'
 59 *        EXPORTING
 60 *          STR        = LS_JSON
 61 *        IMPORTING
 62 *          LEN_VISUAL = LF_LEN_VISUAL.
 63 *
 64 *      IF LF_LEN_VISUAL = 2 . "包含汉字
 65 *        LF_DATA = CL_HTTP_UTILITY=>ESCAPE_URL( LS_JSON ).
 66 *      ELSE .
 67 *        LF_DATA = LS_JSON .
 68 *      ENDIF .
 69     LF_DATA = LS_JSON .
 70 
 71 
 72     DATA: LF_HASH          TYPE  HASH160,
 73           LF_HASHLEN       TYPE  I,
 74           LF_HASHX         TYPE  HASH160X,
 75           LF_HASHXLEN      TYPE  I,
 76           LF_HASHSTRING    TYPE  STRING,
 77           LF_HASHXSTRING   TYPE  XSTRING,
 78           LF_HASHB64STRING TYPE  STRING.
 79     DATA LF_SIGN_INPUT TYPE STRING .
 80     LF_SIGN_INPUT = LF_SECRETKEY && LF_SECRET && LF_TIMESTAMP && LF_DATA .
 81     CALL FUNCTION 'CALCULATE_HASH_FOR_CHAR'
 82       EXPORTING
 83         ALG            = 'MD5'
 84         DATA           = LF_SIGN_INPUT
 85         LENGTH         = 0
 86       IMPORTING
 87         HASH           = LF_HASH
 88         HASHLEN        = LF_HASHLEN
 89         HASHX          = LF_HASHX
 90         HASHXLEN       = LF_HASHXLEN
 91         HASHSTRING     = LF_HASHSTRING
 92         HASHXSTRING    = LF_HASHXSTRING
 93         HASHB64STRING  = LF_HASHB64STRING
 94       EXCEPTIONS
 95         UNKNOWN_ALG    = 1
 96         PARAM_ERROR    = 2
 97         INTERNAL_ERROR = 3
 98         OTHERS         = 4.
 99     LF_SIGN = LF_HASHSTRING .
100 
101 
102 
103 
104     DATA: LF_MESSAGE TYPE STRING,
105           LF_TYPE    TYPE CHAR1.
106     CLEAR: LF_TYPE ,LF_MESSAGE .
107 
108     DATA LC_HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT.
109     DATA LF_REQ_URL TYPE STRING .
110     DATA LF_REQUEST_BODY TYPE STRING .
111     DATA LF_LEN TYPE I .
112     DATA LF_RESPONSE_STRING TYPE STRING .
113     DATA LF_REQUEST_BODYX TYPE XSTRING .
114 * 1. 创建http对象
115     CLEAR: LF_TIMESTAMPL_B ,LF_TIMESTAMPL_E .
116     GET TIME STAMP FIELD LF_TIMESTAMPL_B.
117     CLEAR: LF_REQ_URL .
118     LF_REQ_URL = LF_BASE_URL && LF_JIEKOU  .
119     CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
120       EXPORTING
121         URL                = LF_REQ_URL
122       IMPORTING
123         CLIENT             = LC_HTTP_CLIENT
124       EXCEPTIONS
125         ARGUMENT_NOT_FOUND = 1
126         PLUGIN_NOT_ACTIVE  = 2
127         INTERNAL_ERROR     = 3
128         OTHERS             = 4.
129     IF SY-SUBRC <> 0 .
130       LF_MESSAGE = '未能访问到网址' .
131       LF_TYPE = 'E' .
132       EXIT .
133     ENDIF .
134 *2.REQUEST 对象 设定编码格式
135     LC_HTTP_CLIENT->REQUEST->SET_CONTENT_TYPE( CONTENT_TYPE = 'application/json; charset=utf-8' ).
136 *      LC_HTTP_CLIENT->REQUEST->SET_CONTENT_TYPE( CONTENT_TYPE = 'application/json' )..
137 *3.REQUEST 对象 设定调用服务
138     LC_HTTP_CLIENT->REQUEST->SET_METHOD( IF_HTTP_REQUEST=>CO_REQUEST_METHOD_POST ).
139 
140 *4. 设置待传输内容
141 
142     LF_REQUEST_BODY  = '{"secretKey":'  && '"' && LF_SECRETKEY && '",'
143                       && '"timeStamp":' &&  LF_TIMESTAMP && ','
144                       && '"sign":' && '"' && LF_SIGN && '",'
145                       && '"data":' && LF_DATA && '}'.
146 
147     CLEAR LF_LEN .
148     LF_LEN = STRLEN( LF_REQUEST_BODY ).
149     DATA LF_LENC TYPE STRING .
150     LF_LENC = LF_LEN .
151 *      LC_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD( NAME = 'Content-Length' VALUE = LF_LENC  ).
152     LC_HTTP_CLIENT->REQUEST->SET_CDATA( DATA = LF_REQUEST_BODY OFFSET = 0 LENGTH = LF_LEN ).
153 *      LC_HTTP_CLIENT->REQUEST->SET_CDATA( DATA = LF_REQUEST_BODY ).
154 
155 
156 *5. 发送请求
157     LC_HTTP_CLIENT->SEND(
158          EXPORTING
159            TIMEOUT                     = IF_HTTP_CLIENT=>CO_TIMEOUT_DEFAULT
160           EXCEPTIONS
161             HTTP_COMMUNICATION_FAILURE = 1
162             HTTP_INVALID_STATE         = 2
163             HTTP_PROCESSING_FAILED     = 3
164             HTTP_INVALID_TIMEOUT       = 4
165             OTHERS                     = 5 ).
166     IF SY-SUBRC <> 0.
167       "操作失败,获取失败原因
168       LC_HTTP_CLIENT->GET_LAST_ERROR( IMPORTING MESSAGE = LF_MESSAGE  ).
169       LF_TYPE = 'E' .
170       EXIT.
171     ENDIF.
172 *6. RESPONSE 对象
173     LC_HTTP_CLIENT->RECEIVE(
174     EXCEPTIONS
175       HTTP_COMMUNICATION_FAILURE = 1
176       HTTP_INVALID_STATE         = 2
177       HTTP_PROCESSING_FAILED     = 3
178       OTHERS                     = 4 ).
179     IF SY-SUBRC = 0 .
180       CLEAR: LF_RESPONSE_STRING .
181       LF_RESPONSE_STRING  = LC_HTTP_CLIENT->RESPONSE->GET_CDATA( ).
182     ELSE .
183       LC_HTTP_CLIENT->GET_LAST_ERROR( IMPORTING MESSAGE = LF_MESSAGE CODE    = DATA(G_SUBRC) ).
184     ENDIF .
185     GET TIME STAMP FIELD LF_TIMESTAMPL_E.
186 
187 
188 
189     TYPES: BEGIN OF TY_RESULT ,
190              CODE    TYPE STRING,
191              MESSAGE TYPE STRING,
192            END OF TY_RESULT .
193     DATA: LS_RESULT TYPE TY_RESULT .
194     CLEAR LS_RESULT .
195 
196     /UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON = LF_RESPONSE_STRING ASSOC_ARRAYS = ABAP_TRUE ASSOC_ARRAYS_OPT = ABAP_TRUE CHANGING DATA =  LS_RESULT ).
197     CLEAR LF_RESPONSE_STRING .
198     IF LS_RESULT-CODE = '0'.
199 
200     ELSE .
201       LF_TYPE = 'E' .
202       LF_MESSAGE = LS_RESULT-CODE && ':' &&  LS_RESULT-MESSAGE .
203     ENDIF.
204 * {"code":0,"message":"success","data":null}
205 
206 
207     IF LF_TYPE = 'E' .
208       GS_ALV-MESSAGE = LF_MESSAGE .
209 
210       LS_ZTMT014ERR-TOR_ID = GS_ALV-TOR_ID .
211       LS_ZTMT014ERR-ZDATUM = SY-DATUM .
212       LS_ZTMT014ERR-ZUZEIT = SY-UZEIT .
213       LS_ZTMT014ERR-CODE = LS_RESULT-CODE .
214       LS_ZTMT014ERR-ERRMESSAGE = LS_RESULT-MESSAGE .
215       APPEND LS_ZTMT014ERR TO LT_ZTMT014ERR .
216       CLEAR LS_ZTMT014ERR .
217     ELSE .
218       GS_ALV-MESSAGE = '成功:已传输至小程序'.
219       LS_ZTMT014-TOR_ID = GS_ALV-TOR_ID .
220       LS_ZTMT014-ZDATUM = SY-DATUM .
221       LS_ZTMT014-ZUZEIT = SY-UZEIT .
222       CALL FUNCTION 'CIF_GEN4_CONVERT_DATETIME'
223         EXPORTING
224           IV_DATE                = LS_ZTMT014-ZDATUM
225           IV_TIME                = LS_ZTMT014-ZUZEIT
226           IV_TIMEZONE            = 'UTC+8'
227         IMPORTING
228           EV_TIMESTAMP           = LS_ZTMT014-CHANGED_ON
229         EXCEPTIONS
230           TIME_CONVERSION_FAILED = 1
231           OTHERS                 = 2.
232       APPEND LS_ZTMT014 TO LT_ZTMT014 .
233       CLEAR LS_ZTMT014 .
234     ENDIF.
235 
236 
237 
238     DATA: LT_ZTMT014_TIME TYPE TABLE OF ZTMT014_TIME,
239           LS_ZTMT014_TIME TYPE ZTMT014_TIME.
240     CLEAR: LT_ZTMT014_TIME ,LT_ZTMT014_TIME[] .
241 
242     CALL FUNCTION 'GUID_CREATE'
243       IMPORTING
244         EV_GUID_16 = LS_ZTMT014_TIME-ZGUID. " “未加工”格式的 GUID
245     LS_ZTMT014_TIME-TIMESTAMPL_B = LF_TIMESTAMPL_B .
246     LS_ZTMT014_TIME-TIMESTAMPL_E = LF_TIMESTAMPL_E .
247     PERFORM FRM_TIME_JIANGE USING LF_TIMESTAMPL_B LF_TIMESTAMPL_E CHANGING LS_ZTMT014_TIME-ZTIME_JIANGE .
248     LS_ZTMT014_TIME-TOR_ID = GS_ALV-TOR_ID .
249     LS_ZTMT014_TIME-ZDATUM = SY-DATUM .
250     LS_ZTMT014_TIME-ZUZEIT = SY-UZEIT .
251     APPEND LS_ZTMT014_TIME TO LT_ZTMT014_TIME .
252     CLEAR LS_ZTMT014_TIME .
253 
254     MODIFY GT_ALV FROM GS_ALV TRANSPORTING MESSAGE .
255     CLEAR GS_ALV .
256 
257 
258 
259     MODIFY ZTMT014ERR FROM TABLE LT_ZTMT014ERR[] .
260     MODIFY ZTMT014 FROM TABLE LT_ZTMT014[] .
261     MODIFY ZTMT014_TIME FROM TABLE LT_ZTMT014_TIME[] .
262     IF SY-SUBRC = 0.
263       COMMIT WORK AND WAIT .
264     ELSE .
265       ROLLBACK WORK .
266     ENDIF.
267 
268     WAIT UP TO 1 SECONDS .
269     CLEAR LS_ALV .
270   ENDLOOP.
View Code
  1 FORM FRM_GET_TOR_DATA USING VALUE(FU_TOR_ROOT_KEY) TYPE /SCMTMS/S_TOR_ROOT_K-KEY
  2                       CHANGING FC_JSON TYPE STRING .
  3 
  4   CLEAR: FC_JSON .
  5 
  6   DATA: LF_DATE TYPE SY-DATUM,
  7         LF_TIME TYPE SY-UZEIT.
  8   DATA: LS_KEYS TYPE /BOBF/S_FRW_KEY,
  9         LT_KEYS TYPE /BOBF/T_FRW_KEY.
 10 
 11   DATA LO_SRV_MGR TYPE REF TO /BOBF/IF_TRA_SERVICE_MANAGER.
 12   DATA LO_CHANGE   TYPE REF TO /BOBF/IF_TRA_CHANGE.
 13   DATA LO_MESSAGE  TYPE REF TO /BOBF/IF_FRW_MESSAGE.
 14 
 15   TRY.
 16       LO_SRV_MGR = /BOBF/CL_TRA_SERV_MGR_FACTORY=>GET_SERVICE_MANAGER( /SCMTMS/IF_TOR_C=>SC_BO_KEY ).
 17     CATCH /BOBF/CX_FRW INTO DATA(LF_FRW).
 18       DATA(LF_ERR_MSG) = LF_FRW->GET_TEXT( ).
 19   ENDTRY .
 20 
 21   CLEAR: LT_KEYS ,LT_KEYS[] .
 22   LS_KEYS-KEY = FU_TOR_ROOT_KEY .
 23   APPEND LS_KEYS TO LT_KEYS .
 24   CLEAR LS_KEYS .
 25 
 26   DATA: LT_ROOT_TOR_DATA TYPE /SCMTMS/T_TOR_ROOT_K,
 27         LS_ROOT_TOR_DATA TYPE /SCMTMS/S_TOR_ROOT_K.
 28   CLEAR: LT_ROOT_TOR_DATA ,LT_ROOT_TOR_DATA[] .
 29   LO_SRV_MGR->RETRIEVE(
 30     EXPORTING
 31       IV_NODE_KEY = /SCMTMS/IF_TOR_C=>SC_NODE-ROOT
 32       IT_KEY      = LT_KEYS
 33     IMPORTING
 34       EO_MESSAGE  = LO_MESSAGE
 35       EO_CHANGE   = LO_CHANGE
 36       ET_DATA     = LT_ROOT_TOR_DATA ).
 37 
 38   TYPES: BEGIN OF TY_TRQ_009 ,
 39            ZCHLS  TYPE ZTMT009HD-ZCHLS,
 40            ZLX    TYPE ZTMT009HD-ZLX,
 41            TOR_ID TYPE ZTMT009HD-TOR_ID,
 42            TRQ_ID TYPE ZTMT009HD-TRQ_ID,
 43          END OF TY_TRQ_009 .
 44   DATA: LT_TRQ_009 TYPE TABLE OF TY_TRQ_009,
 45         LS_TRQ_009 TYPE TY_TRQ_009.
 46   CLEAR: LT_TRQ_009 ,LT_TRQ_009[] .
 47   IF LT_ROOT_TOR_DATA[] IS NOT INITIAL.
 48     SELECT
 49       ZCHLS
 50       ZLX
 51       TOR_ID
 52       TRQ_ID
 53       INTO CORRESPONDING FIELDS OF TABLE LT_TRQ_009
 54       FROM ZTMT009HD FOR ALL ENTRIES IN LT_ROOT_TOR_DATA
 55       WHERE TOR_ID = LT_ROOT_TOR_DATA-TOR_ID AND
 56             TRQ_ID <> SPACE .
 57   ENDIF.
 58   SORT LT_TRQ_009 BY TRQ_ID .
 59 
 60 
 61   DATA: LT_ITEM_TR TYPE /SCMTMS/T_TOR_ITEM_TR_K,
 62         LS_ITEM_TR TYPE /SCMTMS/S_TOR_ITEM_TR_K.
 63   CLEAR: LT_ITEM_TR ,LT_ITEM_TR[] .
 64   LO_SRV_MGR->RETRIEVE_BY_ASSOCIATION(
 65       EXPORTING
 66         IV_NODE_KEY    = /SCMTMS/IF_TOR_C=>SC_NODE-ROOT
 67         IT_KEY         = LT_KEYS
 68         IV_ASSOCIATION = /SCMTMS/IF_TOR_C=>SC_ASSOCIATION-ROOT-ITEM_TR
 69         IV_FILL_DATA   = ABAP_TRUE
 70         IV_EDIT_MODE   = /BOBF/IF_CONF_C=>SC_EDIT_READ_ONLY
 71       IMPORTING
 72         EO_MESSAGE     = LO_MESSAGE
 73         ET_DATA        = LT_ITEM_TR ).
 74 
 75   DATA: LT_STOP TYPE /SCMTMS/T_TOR_STOP_K,
 76         LS_STOP TYPE /SCMTMS/S_TOR_STOP_K.
 77   CLEAR: LT_STOP ,LT_STOP[] .
 78   LO_SRV_MGR->RETRIEVE_BY_ASSOCIATION(
 79       EXPORTING
 80         IV_NODE_KEY    = /SCMTMS/IF_TOR_C=>SC_NODE-ROOT
 81         IT_KEY         = LT_KEYS
 82         IV_ASSOCIATION = /SCMTMS/IF_TOR_C=>SC_ASSOCIATION-ROOT-STOP
 83         IV_FILL_DATA   = ABAP_TRUE
 84         IV_EDIT_MODE   = /BOBF/IF_CONF_C=>SC_EDIT_READ_ONLY
 85       IMPORTING
 86         EO_MESSAGE     = LO_MESSAGE
 87         ET_DATA        = LT_STOP ) .
 88 
 89 
 90   DATA: LT_HEAD TYPE TABLE OF ZTM014HEAD,
 91         LS_HEAD TYPE ZTM014HEAD.
 92   CLEAR: LT_HEAD ,LT_HEAD[] .
 93   LOOP AT LT_ROOT_TOR_DATA INTO LS_ROOT_TOR_DATA .
 94     LS_HEAD-TOR_ID          = LS_ROOT_TOR_DATA-TOR_ID . " 单据
 95     LS_HEAD-TOR_TYPE        = LS_ROOT_TOR_DATA-TOR_TYPE . " 业务凭证类型
 96     LS_HEAD-TSPID           = LS_ROOT_TOR_DATA-TSPID  . " 运输公司
 97     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
 98       EXPORTING
 99         INPUT  = LS_HEAD-TSPID
100       IMPORTING
101         OUTPUT = LS_HEAD-TSPID.
102 
103     LS_HEAD-EXEC_ORG_ID     = LS_ROOT_TOR_DATA-EXEC_ORG_ID  . " 计划和执行组织
104     LS_HEAD-EXEC_GRP_ID     = LS_ROOT_TOR_DATA-EXEC_GRP_ID  . " 计划和执行组
105     LS_HEAD-LIFECYCLE       = LS_ROOT_TOR_DATA-LIFECYCLE  . " 生命周期状态
106     LS_HEAD-EXECUTION       = LS_ROOT_TOR_DATA-EXECUTION  . " 执行状态
107     LS_HEAD-DELIVERY        = LS_ROOT_TOR_DATA-DELIVERY . " 交货状态
108     LS_HEAD-MTR             = LS_ROOT_TOR_DATA-MTR  . " 运输方式
109     LS_HEAD-MAX_UTIL        = LS_ROOT_TOR_DATA-MAX_UTIL . " 最大利用率
110     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
111       EXPORTING
112         INPUT  = LS_HEAD-MAX_UTIL
113       IMPORTING
114         OUTPUT = LS_HEAD-MAX_UTIL.
115     LS_HEAD-MAX_UTIL_MASS   = LS_ROOT_TOR_DATA-MAX_UTIL_MASS  . " 最大利用率
116     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
117       EXPORTING
118         INPUT  = LS_HEAD-MAX_UTIL_MASS
119       IMPORTING
120         OUTPUT = LS_HEAD-MAX_UTIL_MASS.
121     LS_HEAD-MAX_UTIL_VOLUME = LS_ROOT_TOR_DATA-MAX_UTIL_VOLUME  . " 最大利用率
122     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
123       EXPORTING
124         INPUT  = LS_HEAD-MAX_UTIL_VOLUME
125       IMPORTING
126         OUTPUT = LS_HEAD-MAX_UTIL_VOLUME.
127 
128     LS_HEAD-GRO_WEI_VAL     = LS_ROOT_TOR_DATA-GRO_WEI_VAL  . " 毛重
129     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
130       EXPORTING
131         INPUT  = LS_HEAD-GRO_WEI_VAL
132       IMPORTING
133         OUTPUT = LS_HEAD-GRO_WEI_VAL.
134 
135     LS_HEAD-GRO_WEI_UNI     = LS_ROOT_TOR_DATA-GRO_WEI_UNI  . " 毛重计量单位
136     LS_HEAD-GRO_VOL_VAL     = LS_ROOT_TOR_DATA-GRO_VOL_VAL  . " 总体积
137     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
138       EXPORTING
139         INPUT  = LS_HEAD-GRO_VOL_VAL
140       IMPORTING
141         OUTPUT = LS_HEAD-GRO_VOL_VAL.
142     LS_HEAD-GRO_VOL_UNI     = LS_ROOT_TOR_DATA-GRO_VOL_UNI  . " 总体积计量单位
143     LS_HEAD-CONFIRMATION    = LS_ROOT_TOR_DATA-CONFIRMATION . " 确认状态
144     IF LS_ROOT_TOR_DATA-CREATED_ON IS NOT INITIAL.
145       CLEAR: LF_DATE ,LF_TIME .
146       CALL FUNCTION 'CIF_GEN4_CONVERT_TIMESTAMP'
147         EXPORTING
148           IV_TIMESTAMP           = LS_ROOT_TOR_DATA-CREATED_ON
149           IV_TIMEZONE            = 'UTC+8'
150         IMPORTING
151           EV_DATE                = LF_DATE
152           EV_TIME                = LF_TIME
153         EXCEPTIONS
154           TIME_CONVERSION_FAILED = 1
155           OTHERS                 = 2.
156       LS_HEAD-CRTDT           = LF_DATE  . " 创建日期
157       LS_HEAD-CRTTM           = LF_TIME  . " 创建时间
158     ENDIF.
159 
160 
161     LS_HEAD-CREATED_BY      = LS_ROOT_TOR_DATA-CREATED_BY . " 创建者
162     READ TABLE GT_USER  INTO GS_USER WITH KEY BNAME = LS_ROOT_TOR_DATA-CREATED_BY BINARY SEARCH .
163     IF SY-SUBRC = 0.
164       LS_HEAD-CRTNM           = GS_USER-NAME_TEXT  . " 业务用户描述
165     ENDIF.
166     CLEAR GS_USER .
167 
168     IF LS_ROOT_TOR_DATA-CHANGED_ON IS NOT INITIAL.
169       CLEAR: LF_DATE ,LF_TIME .
170       CALL FUNCTION 'CIF_GEN4_CONVERT_TIMESTAMP'
171         EXPORTING
172           IV_TIMESTAMP           = LS_ROOT_TOR_DATA-CHANGED_ON
173           IV_TIMEZONE            = 'UTC+8'
174         IMPORTING
175           EV_DATE                = LF_DATE
176           EV_TIME                = LF_TIME
177         EXCEPTIONS
178           TIME_CONVERSION_FAILED = 1
179           OTHERS                 = 2.
180       LS_HEAD-CHGDT           = LF_DATE  . " 更改日期
181       LS_HEAD-CHGTM           = LF_TIME  . " 更改时间
182     ENDIF.
183 
184     LS_HEAD-CHANGED_BY      = LS_ROOT_TOR_DATA-CHANGED_BY . " 创建者
185     READ TABLE GT_USER  INTO GS_USER WITH KEY BNAME = LS_ROOT_TOR_DATA-CHANGED_BY BINARY SEARCH .
186     IF SY-SUBRC = 0.
187       LS_HEAD-CHGNM            = GS_USER-NAME_TEXT  . " 业务用户描述
188     ENDIF.
189     CLEAR GS_USER .
190 
191     LS_HEAD-TOTAL_DISTANCE_KM   = LS_ROOT_TOR_DATA-TOTAL_DISTANCE_KM  . " 总距离 (km)
192     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
193       EXPORTING
194         INPUT  = LS_HEAD-TOTAL_DISTANCE_KM
195       IMPORTING
196         OUTPUT = LS_HEAD-TOTAL_DISTANCE_KM.
197     LS_HEAD-TOTAL_DURATION_NET  = LS_ROOT_TOR_DATA-TOTAL_DURATION_NET . " 总计净持续时间
198     CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
199       EXPORTING
200         INPUT  = LS_HEAD-TOTAL_DURATION_NET
201       IMPORTING
202         OUTPUT = LS_HEAD-TOTAL_DURATION_NET.
203     READ TABLE LT_ITEM_TR INTO LS_ITEM_TR WITH KEY ROOT_KEY = LS_ROOT_TOR_DATA-KEY
204                                                    ITEM_CAT = 'AVR'  .
205     IF SY-SUBRC = 0.
206       LS_HEAD-RES_ID              = LS_ITEM_TR-RES_ID . " 资源
207       LS_HEAD-PLATENUMBER         = LS_ITEM_TR-PLATENUMBER  . " 注册编号
208       SELECT SINGLE  DESCRIPTION INTO LS_HEAD-ZXLMS FROM /SCMTMS/D_SCHDSC
209         WHERE PARENT_KEY = LS_ITEM_TR-SCHED_KEY AND
210               LANGUAGE_CODE = SY-LANGU.
211 *20210624
212       SELECT SINGLE  SCH_ID INTO LS_HEAD-SCH_ID FROM /SCMTMS/D_SCHROT
213       WHERE DB_KEY = LS_ITEM_TR-SCHED_KEY .
214     ENDIF.
215     CLEAR LS_ITEM_TR .
216 
217     APPEND LS_HEAD TO LT_HEAD .
218     CLEAR LS_HEAD .
219 
220     CLEAR LS_ROOT_TOR_DATA .
221   ENDLOOP.
222 
223   DATA: LT_ZDRIVER TYPE TABLE OF ZTM014ZDRIVER,
224         LS_ZDRIVER TYPE  ZTM014ZDRIVER.
225   CLEAR: LT_ZDRIVER ,LT_ZDRIVER[] .
226 
227   LOOP AT LT_ITEM_TR INTO LS_ITEM_TR WHERE ITEM_CAT = 'DRI' .
228     READ TABLE LT_ROOT_TOR_DATA INTO LS_ROOT_TOR_DATA WITH KEY KEY = LS_ITEM_TR-ROOT_KEY .
229     IF SY-SUBRC = 0.
230       LS_ZDRIVER-TOR_ID     = LS_ROOT_TOR_DATA-TOR_ID . "单据
231       LS_ZDRIVER-ITEM_ID    = LS_ITEM_TR-ITEM_ID . " 项目
232       LS_ZDRIVER-RES_ID     = LS_ITEM_TR-RES_ID ."  资源
233       LS_ZDRIVER-ITEM_DESCR = LS_ITEM_TR-ITEM_DESCR ." 项目描述
234       APPEND LS_ZDRIVER TO LT_ZDRIVER .
235       CLEAR LS_ZDRIVER .
236     ENDIF.
237     CLEAR LS_ROOT_TOR_DATA .
238 
239     CLEAR LS_ITEM_TR .
240   ENDLOOP.
241 
242   DATA: LT_ZCARGO TYPE TABLE OF ZTM014ZCARGO,
243         LS_ZCARGO TYPE ZTM014ZCARGO.
244   CLEAR: LT_ZCARGO ,LT_ZCARGO[] .
245   LOOP AT LT_ITEM_TR INTO LS_ITEM_TR WHERE ORIG_REF_BO = 'TRQ' .
246     IF LS_ITEM_TR-ITEM_CAT <> 'PRD'.
247       READ TABLE LT_ROOT_TOR_DATA INTO LS_ROOT_TOR_DATA WITH KEY KEY = LS_ITEM_TR-ROOT_KEY .
248       IF SY-SUBRC = 0.
249         LS_ZCARGO-TOR_ID            = LS_ROOT_TOR_DATA-TOR_ID . " 单据
250         LS_ZCARGO-ITEM_ID           = LS_ITEM_TR-ITEM_ID  . " 项目
251         LS_ZCARGO-KEY               = LS_ITEM_TR-KEY  . " 运输订单项目的键值
252         LS_ZCARGO-ITEM_PARENT_KEY   = LS_ITEM_TR-ITEM_PARENT_KEY  . " 运输订单项目的键值
253         LS_ZCARGO-ITEM_DESCR        = LS_ITEM_TR-ITEM_DESCR . " 项目描述
254         LS_ZCARGO-ITEM_CAT          = LS_ITEM_TR-ITEM_CAT . " 项目类别
255         LS_ZCARGO-MAIN_CARGO_ITEM   = LS_ITEM_TR-MAIN_CARGO_ITEM  . " 主货物项目
256         LS_ZCARGO-SHIPPER_ID        = LS_ITEM_TR-SHIPPER_ID . " 发货方
257         LS_ZCARGO-CONSIGNEE_ID      = LS_ITEM_TR-CONSIGNEE_ID . " 收货方
258         LS_ZCARGO-GRO_WEI_VAL       = LS_ITEM_TR-GRO_WEI_VAL  . " 毛重
259 *20210624
260         LS_ZCARGO-SRC_STOP_KEY        = LS_ITEM_TR-SRC_STOP_KEY . " 提货站点KEY值
261         LS_ZCARGO-DES_STOP_KEY        = LS_ITEM_TR-DES_STOP_KEY . " 卸货站点KEY值
262         LS_ZCARGO-AMT_GDSV_VAL        = LS_ITEM_TR-AMT_GDSV_VAL  . " 货物价值
263         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
264           EXPORTING
265             INPUT  = LS_ZCARGO-AMT_GDSV_VAL
266           IMPORTING
267             OUTPUT = LS_ZCARGO-AMT_GDSV_VAL.
268 
269         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
270           EXPORTING
271             INPUT  = LS_ZCARGO-GRO_WEI_VAL
272           IMPORTING
273             OUTPUT = LS_ZCARGO-GRO_WEI_VAL.
274         LS_ZCARGO-GRO_WEI_UNI       = LS_ITEM_TR-GRO_WEI_UNI  . " 毛重计量单位
275         LS_ZCARGO-GRO_VOL_VAL       = LS_ITEM_TR-GRO_VOL_VAL  . " 总体积
276         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
277           EXPORTING
278             INPUT  = LS_ZCARGO-GRO_VOL_VAL
279           IMPORTING
280             OUTPUT = LS_ZCARGO-GRO_VOL_VAL.
281         LS_ZCARGO-GRO_VOL_UNI       = LS_ITEM_TR-GRO_VOL_UNI  . " 总体积计量单位
282         LS_ZCARGO-NET_WEI_VAL       = LS_ITEM_TR-NET_WEI_VAL  . " 净重
283         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
284           EXPORTING
285             INPUT  = LS_ZCARGO-NET_WEI_VAL
286           IMPORTING
287             OUTPUT = LS_ZCARGO-NET_WEI_VAL.
288         LS_ZCARGO-NET_WEI_UNI       = LS_ITEM_TR-NET_WEI_UNI  . " 净重计量单位
289         LS_ZCARGO-QUA_PCS_VAL       = LS_ITEM_TR-QUA_PCS_VAL  . " 数量
290         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
291           EXPORTING
292             INPUT  = LS_ZCARGO-QUA_PCS_VAL
293           IMPORTING
294             OUTPUT = LS_ZCARGO-QUA_PCS_VAL.
295         LS_ZCARGO-QUA_PCS_UNI       = LS_ITEM_TR-QUA_PCS_UNI  . " 数量计量单位
296         CALL FUNCTION 'ZNUMBER_CONV_OUTPUT'
297           EXPORTING
298             INPUT  = LS_ZCARGO-QUA_PCS_UNI
299           IMPORTING
300             OUTPUT = LS_ZCARGO-QUA_PCS_UNI.
301         LS_ZCARGO-PKGUN_WEI_UNI     = LS_ITEM_TR-PKGUN_WEI_UNI  . " 皮重计量单位
302         SELECT SINGLE TRQ_ID INTO LS_ZCARGO-TRQ_ID  FROM /SCMTMS/D_TRQROT
303           WHERE DB_KEY = LS_ITEM_TR-ORIG_REF_ROOT . " 代运单或代运报价中的项目类型
304         SELECT SINGLE ITEM_TYPE INTO LS_ZCARGO-ITEM_TYPE  FROM /SCMTMS/D_TRQITM
305           WHERE DB_KEY = LS_ITEM_TR-ORIG_REF_ITEM AND
306                 PARENT_KEY = LS_ITEM_TR-ORIG_REF_ROOT . " 代运单或代运报价中的项目类型
307         SELECT SINGLE DESCRIPTION_S INTO LS_ZCARGO-ZXMLXMS FROM /SCMTMS/C_TRQITT
308           WHERE LANGU = SY-LANGU AND ITEM_TYPE = LS_ZCARGO-ITEM_TYPE ." 项目类型的描述
309         LS_ZCARGO-PRODUCT_ID        = LS_ITEM_TR-PRODUCT_ID . " 产品
310         LS_ZCARGO-TRANSSRVLVL_CODE  = LS_ITEM_TR-TRANSSRVLVL_CODE . " 运输服务级别 - 销售
311         SELECT SINGLE VTEXT INTO LS_ZCARGO-ZFWJBMS  FROM TVSBT
312           WHERE VSBED = LS_ITEM_TR-TRANSSRVLVL_CODE AND SPRAS = SY-LANGU . " 运输服务级别描述
313         READ TABLE LT_STOP INTO LS_STOP WITH KEY KEY = LS_ITEM_TR-SRC_STOP_KEY .
314         IF SY-SUBRC = 0.
315           LS_ZCARGO-SRC_LOC_IDTRQ     = LS_STOP-LOG_LOCID  . " 源位置
316         ENDIF.
317         CLEAR LS_STOP .
318 
319         READ TABLE LT_STOP INTO LS_STOP WITH KEY KEY = LS_ITEM_TR-DES_STOP_KEY .
320         IF SY-SUBRC = 0.
321           LS_ZCARGO-DES_LOC_IDTRQ      = LS_STOP-LOG_LOCID  . " 目标位置
322         ENDIF.
323         CLEAR LS_STOP .
324 
325         IF LS_ITEM_TR-ASSGN_START IS NOT INITIAL.
326           CLEAR: LF_DATE ,LF_TIME .
327           CALL FUNCTION 'CIF_GEN4_CONVERT_TIMESTAMP'
328             EXPORTING
329               IV_TIMESTAMP           = LS_ITEM_TR-ASSGN_START
330               IV_TIMEZONE            = 'UTC+8'
331             IMPORTING
332               EV_DATE                = LF_DATE
333               EV_TIME                = LF_TIME
334             EXCEPTIONS
335               TIME_CONVERSION_FAILED = 1
336               OTHERS                 = 2.
337           LS_ZCARGO-ASSGN_DT            = LF_DATE  . " 计划提货日期
338           LS_ZCARGO-ASSGN_TM           = LF_TIME  . " 计划提货时间
339         ENDIF.
340 
341         IF LS_ITEM_TR-UNASSGN_START IS NOT INITIAL.
342           CLEAR: LF_DATE ,LF_TIME .
343           CALL FUNCTION 'CIF_GEN4_CONVERT_TIMESTAMP'
344             EXPORTING
345               IV_TIMESTAMP           = LS_ITEM_TR-UNASSGN_START
346               IV_TIMEZONE            = 'UTC+8'
347             IMPORTING
348               EV_DATE                = LF_DATE
349               EV_TIME                = LF_TIME
350             EXCEPTIONS
351               TIME_CONVERSION_FAILED = 1
352               OTHERS                 = 2.
353           LS_ZCARGO-UNASSGN_DT           = LF_DATE  . " 计划交货日期
354           LS_ZCARGO-UNASSGN_TM           = LF_TIME  . " 计划交货时间
355         ENDIF.
356         READ TABLE LT_TRQ_009 INTO LS_TRQ_009 WITH KEY TRQ_ID = LS_ZCARGO-TRQ_ID BINARY SEARCH .
357         IF SY-SUBRC <> 0.
358           APPEND LS_ZCARGO TO LT_ZCARGO .
359         ENDIF.
360         CLEAR LS_TRQ_009 .
361 
362         CLEAR LS_ZCARGO .
363 
364       ENDIF.
365       CLEAR LS_ROOT_TOR_DATA .
366     ENDIF.
367 
368     CLEAR LS_ITEM_TR .
369   ENDLOOP.
370 
371   DATA: LT_ZSTOP TYPE TABLE OF ZTM014ZSTOP,
372         LS_ZSTOP TYPE ZTM014ZSTOP.
373   CLEAR: LT_ZSTOP ,LT_ZSTOP[] .
374   LOOP AT LT_STOP INTO LS_STOP.
375     READ TABLE LT_ROOT_TOR_DATA INTO LS_ROOT_TOR_DATA WITH KEY KEY = LS_STOP-ROOT_KEY .
376     IF SY-SUBRC = 0 .
377       LS_ZSTOP-TOR_ID    =    LS_ROOT_TOR_DATA-TOR_ID    .    "    单据
378       LS_ZSTOP-KEY  = LS_STOP-KEY  . " 运输订单的站的键值
379       LS_ZSTOP-STOP_ID  = LS_STOP-STOP_ID . " 运输订单的站的键值
380       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
381         EXPORTING
382           INPUT  = LS_ZSTOP-STOP_ID
383         IMPORTING
384           OUTPUT = LS_ZSTOP-STOP_ID.
385 
386       LS_ZSTOP-STOP_CAT = LS_STOP-STOP_CAT  . " 站类别
387       LS_ZSTOP-LOG_LOCID  = LS_STOP-LOG_LOCID  . " 位置
388 
389       IF LS_STOP-PLAN_TRANS_TIME IS NOT INITIAL.
390         CLEAR: LF_DATE ,LF_TIME .
391         CALL FUNCTION 'CIF_GEN4_CONVERT_TIMESTAMP'
392           EXPORTING
393             IV_TIMESTAMP           = LS_STOP-PLAN_TRANS_TIME
394             IV_TIMEZONE            = 'UTC+8'
395           IMPORTING
396             EV_DATE                = LF_DATE
397             EV_TIME                = LF_TIME
398           EXCEPTIONS
399             TIME_CONVERSION_FAILED = 1
400             OTHERS                 = 2.
401         LS_ZSTOP-PLAN_TRANS_DT           = LF_DATE  . " 运输计划日期
402         LS_ZSTOP-PLAN_TRANS_TM           = LF_TIME  . " 运输计划时间
403       ENDIF.
404 
405       LS_ZSTOP-STOP_SEQ_POS = LS_STOP-STOP_SEQ_POS  . " 在运输站顺序中的站位置
406       APPEND LS_ZSTOP TO LT_ZSTOP .
407       CLEAR LS_ZSTOP .
408     ENDIF.
409     CLEAR LS_ROOT_TOR_DATA .
410 
411 
412     CLEAR LS_STOP .
413   ENDLOOP.
414 
415   DATA: LT_ZSTOP_TMP TYPE TABLE OF ZTM014ZSTOP,
416         LS_ZSTOP_TMP TYPE ZTM014ZSTOP.
417   CLEAR: LT_ZSTOP_TMP ,LT_ZSTOP_TMP[] .
418   LT_ZSTOP_TMP[]  = LT_ZSTOP[]  .
419   CLEAR: LT_ZSTOP ,LT_ZSTOP[] .
420   SORT LT_ZSTOP_TMP BY PLAN_TRANS_DT PLAN_TRANS_TM .
421   LOOP AT LT_ZSTOP_TMP INTO LS_ZSTOP_TMP WHERE STOP_SEQ_POS = 'F' .
422     APPEND LS_ZSTOP_TMP TO LT_ZSTOP .
423     CLEAR LS_ZSTOP_TMP .
424   ENDLOOP.
425   LOOP AT LT_ZSTOP_TMP INTO LS_ZSTOP_TMP WHERE STOP_SEQ_POS <>  'F' AND STOP_SEQ_POS <>  'L' .
426     APPEND LS_ZSTOP_TMP TO LT_ZSTOP .
427     CLEAR LS_ZSTOP_TMP .
428   ENDLOOP.
429   LOOP AT LT_ZSTOP_TMP INTO LS_ZSTOP_TMP WHERE STOP_SEQ_POS = 'L' .
430     APPEND LS_ZSTOP_TMP TO LT_ZSTOP .
431     CLEAR LS_ZSTOP_TMP .
432   ENDLOOP.
433   LOOP AT LT_ZSTOP INTO LS_ZSTOP WHERE STOP_CAT <> 'O' AND STOP_SEQ_POS <> 'I'  .
434     LS_ZSTOP-ORDERE = LS_ZSTOP-ORDERE + 1.
435     MODIFY LT_ZSTOP FROM LS_ZSTOP TRANSPORTING ORDERE.
436     CLEAR LS_ZSTOP .
437   ENDLOOP.
438   CLEAR: LT_ZSTOP_TMP ,LT_ZSTOP_TMP[] .
439 
440 
441   TYPES: TT_ZTM014ZCARGO  TYPE STANDARD TABLE OF ZTM014ZCARGO WITH NON-UNIQUE KEY TOR_ID ITEM_ID.
442   TYPES: TT_ZTM014ZSTOP   TYPE STANDARD TABLE OF ZTM014ZSTOP WITH NON-UNIQUE KEY TOR_ID KEY.
443   TYPES: TT_ZTM014ZDRIVER TYPE STANDARD TABLE OF ZTM014ZDRIVER WITH NON-UNIQUE KEY TOR_ID ITEM_ID.
444 
445   TYPES: BEGIN OF TY_JSON .
446            INCLUDE TYPE ZTM014HEAD .
447   TYPES:   ZCARGO TYPE TT_ZTM014ZCARGO.
448   TYPES:   ZDRIVER TYPE TT_ZTM014ZDRIVER.
449   TYPES:   ZSTOP TYPE TT_ZTM014ZSTOP.
450   TYPES:  END OF TY_JSON .
451   DATA: LS_JSON TYPE TY_JSON .
452   CLEAR LS_JSON .
453   READ TABLE LT_HEAD INTO LS_HEAD INDEX 1 .
454   IF SY-SUBRC = 0.
455     MOVE-CORRESPONDING LS_HEAD TO LS_JSON .
456     LS_JSON-ZCARGO[] = LT_ZCARGO[] .
457     LS_JSON-ZSTOP[] = LT_ZSTOP[] .
458     LS_JSON-ZDRIVER[] = LT_ZDRIVER[] .
459   ENDIF.
460   CLEAR LS_HEAD .
461 
462 
463   CLEAR FC_JSON .
464   FC_JSON = /UI2/CL_JSON=>SERIALIZE( DATA = LS_JSON PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-LOW_CASE ASSOC_ARRAYS = ABAP_TRUE ASSOC_ARRAYS_OPT = ABAP_TRUE ).
465 
466 
467 ENDFORM.
View Code

 

posted on 2021-07-23 18:19  雨水果冻  阅读(320)  评论(0编辑  收藏  举报