‎2006 Jun 29 7:26 AM
Hi all,
I have placed fields on concatenate statement..separeted by tab space..but if the field contains null value i have placed tab space by using MACROS ..but i found it is taking more runtime and it is outdated...so any body can suggest any other method for the below code....
REPORT ztest1 LINE-SIZE 200.
TABLES : ekko,ekpo.
*for tab delimiter
CONSTANTS : c_tab TYPE x VALUE '09'.
*for total value
DATA : v_total1 TYPE p DECIMALS 2,
v_total(15) TYPE c.
*output string
DATA : output_string1 TYPE string,
output_string2 TYPE string,
output_string3 TYPE string,
output_string4 TYPE string,
output_string5 TYPE string,
output_string6 TYPE string.
*for selection based on creation date and document type
SELECT-OPTIONS : so_aedat FOR ekko-aedat,
so_bsart FOR ekko-bsart.
*File Detail Record
*Purchasing Document Header
DATA : BEGIN OF lt_ekko OCCURS 0,
lv_record_identifier2(3) TYPE c,
lv_org_id1(4) TYPE c,
ebeln LIKE ekko-ebeln, " Purchasing Document Number
aedat LIKE ekko-aedat, " Date on which the record was
" created
bedat LIKE ekko-bedat, " Purchasing document date
bsart LIKE ekko-bsart, " Purchasing document type
lifnr LIKE ekko-lifnr, " Vendor's account number
zsrm_pcnum LIKE ekko-zsrm_pcnum, " SRM: Procurement card number
bukrs LIKE ekko-bukrs, " Company Code
name1 LIKE lfa1-name1, " Name 1
END OF lt_ekko.
*Purchasing Document Item
DATA : BEGIN OF lt_ekpo OCCURS 0,
ebeln LIKE ekpo-ebeln, " Purchasing Document Number
ebelp LIKE ekpo-ebelp, " Item Number of Purchasing Document
aedat LIKE ekpo-aedat, " Purchasing document item change date
vrtkz LIKE ekpo-vrtkz, " Distribution indicator for multiple
" account assignment
afnam LIKE ekpo-afnam, " Name of requisitioner/requester
txz01 LIKE ekpo-txz01, " Short text
netwr LIKE ekpo-netwr, " Net order value in PO currency
menge LIKE ekpo-menge, " Purchase order quantity
knttp LIKE ekpo-knttp, " Account assignment category
mwskz TYPE ekpo-mwskz, " Tax on sales/purchases code
END OF lt_ekpo.
*Account Assignment in Purchasing Document
DATA : BEGIN OF lt_ekkn OCCURS 0,
ebeln LIKE ekkn-ebeln, " Purchasing Document Number
ebelp LIKE ekkn-ebelp, " Item Number of Purchasing Document
zekkn LIKE ekkn-zekkn, " Sequential number of account
" assignment
vproz LIKE ekkn-vproz, " Distribution percentage in the case
" of multiple acct assgt
sakto LIKE ekkn-sakto, " G/L account number
kostl LIKE ekkn-kostl, " Cost Center
ps_psp_pnr LIKE ekkn-ps_psp_pnr, " Work breakdown structure
" element (WBS element)
aufnr LIKE ekkn-aufnr, " Order Number
END OF lt_ekkn.
*Scheduling Agreement Schedule Lines
DATA : BEGIN OF lt_eket OCCURS 0,
ebeln LIKE eket-ebeln, " Purchasing Document Number
ebelp LIKE eket-ebelp, " Item Number of Purchasing Document
eindt LIKE eket-eindt, " Item delivery date
END OF lt_eket.
*Organization Footer Record
DATA : lv_record_identifier3(3) TYPE c VALUE '130',
lv_org_id2(4) TYPE c VALUE '1744',
lv_org_name1(60) TYPE c VALUE 'CLICK',
lv_detail_record_count(5) TYPE c.
*File Footer Record
DATA : lv_record_identifier4(3) TYPE c VALUE '140',
lv_extract_record_count(5) TYPE c,
lv_file_record_count(5) TYPE c.
*for date and time format
lv_creation_date = sy-datum.
lv_creation_time = sy-uzeit.
*concatenate for File Header Record
CONCATENATE lv_record_identifier
lv_sp_id
lv_sp_name
lv_creation_date
lv_creation_time
lv_file_format
lv_file_version
INTO output_string1
SEPARATED BY c_tab.
WRITE 😕 output_string1.
*concatenate Organization Header Record
CONCATENATE lv_record_identifier1
lv_org_id
lv_org_name
INTO output_string2
SEPARATED BY c_tab.
WRITE 😕 output_string2.
*selection of fields
SELECT ebeln
aedat
bsart
zsrm_pcnum
lifnr
bukrs
FROM ekko
INTO CORRESPONDING FIELDS OF TABLE lt_ekko
WHERE ( aedat IN so_aedat OR aedat = sy-datum )
WHERE bsart IN so_bsart
AND ( bsart = 'ECDP' OR bsart = 'ECPO' )
AND zsrm_pcnum IS not NULL.
IF NOT lt_ekko[] IS INITIAL.
SELECT ebeln
ebelp
aedat
vrtkz
afnam
txz01
netwr
menge
knttp
mwskz
FROM ekpo
INTO TABLE lt_ekpo
FOR ALL ENTRIES IN lt_ekko
WHERE ebeln = lt_ekko-ebeln
AND ( aedat IN so_aedat ).
ENDIF.
IF NOT lt_ekpo[] IS INITIAL.
SELECT ebeln
ebelp
zekkn
vproz
sakto
kostl
ps_psp_pnr
aufnr
FROM ekkn
INTO TABLE lt_ekkn
FOR ALL ENTRIES IN lt_ekpo
WHERE ebeln = lt_ekpo-ebeln
AND ebelp = lt_ekpo-ebelp.
SELECT ebeln
ebelp
eindt
FROM eket
INTO TABLE lt_eket
FOR ALL ENTRIES IN lt_ekpo
WHERE ebeln = lt_ekpo-ebeln
AND ebelp = lt_ekpo-ebelp.
ENDIF.
*for specifying the record length
*describe table lt_ekko LINES record_count.
lv_record_count = sy-dbcnt.
lv_detail_record_count = lv_record_count.
lv_extract_record_count = lv_record_count - 2.
lv_file_record_count = lv_record_count + 4.
SHIFT lv_detail_record_count LEFT DELETING LEADING space.
SHIFT lv_extract_record_count LEFT DELETING LEADING space.
SHIFT lv_file_record_count LEFT DELETING LEADING space.
<b>*for macro declaration
DEFINE macro_check_value.
if &1 is initial.
&1 = '%'.
endif.
END-OF-DEFINITION.</b>
*concatenate for File Detail Record
LOOP AT lt_ekko.
SELECT SINGLE name1 FROM lfa1 INTO lt_ekko-name1
WHERE lifnr = lt_ekko-lifnr.
CLEAR v_total1.
LOOP AT lt_ekpo WHERE ebeln = lt_ekko-ebeln.
v_total1 = v_total1 + lt_ekpo-netwr.
MOVE v_total1 TO v_total.
SHIFT v_total LEFT DELETING LEADING space.
ENDLOOP.
LOOP AT lt_ekpo WHERE ebeln = lt_ekko-ebeln.
READ TABLE lt_ekkn WITH KEY ebeln = lt_ekpo-ebeln
ebelp = lt_ekpo-ebelp BINARY SEARCH.
READ TABLE lt_eket WITH KEY ebeln = lt_ekpo-ebeln
ebelp = lt_ekpo-ebelp BINARY SEARCH.
*clearing zeros for integer values
CLEAR : v_netwr,v_menge,v_vproz.
v_netwr = lt_ekpo-netwr.
SHIFT v_netwr LEFT DELETING LEADING space.
v_menge = lt_ekpo-menge.
SHIFT v_menge LEFT DELETING LEADING space.
for vrtkz field
IF lt_ekpo-vrtkz EQ '1' OR lt_ekpo-vrtkz EQ '2'.
MOVE 'M' TO v_vrtkz.
ELSE.
MOVE 'S' TO v_vrtkz.
ENDIF.
for vproz field
IF lt_ekkn-vproz EQ '0.0'.
MOVE '100.0' TO v_vproz.
ELSE.
MOVE lt_ekkn-vproz TO v_vproz.
ENDIF.
SHIFT v_vproz LEFT DELETING LEADING space.
*for knttp value
CASE lt_ekpo-knttp.
WHEN 'K'.
MOVE lt_ekkn-kostl TO v_knttp.
WHEN 'P'.
MOVE lt_ekkn-ps_psp_pnr TO v_knttp.
WHEN 'O'.
MOVE lt_ekkn-aufnr TO v_knttp.
WHEN OTHERS.
MOVE lt_ekpo-knttp TO v_knttp.
ENDCASE.
SHIFT v_knttp LEFT DELETING LEADING space.
CLEAR output_string3.
<b>*macro declaration for tab space for null values
macro_check_value lt_ekko-lv_record_identifier2.
macro_check_value lt_ekko-lv_org_id1.
macro_check_value v_vrtkz.
macro_check_value lt_ekko-ebeln.
macro_check_value lt_ekko-lifnr.
macro_check_value lt_ekko-name1.
macro_check_value v_total.
macro_check_value lt_ekko-aedat.
macro_check_value lt_ekko-zsrm_pcnum.
macro_check_value lt_ekpo-afnam.
macro_check_value lt_ekpo-txz01.
macro_check_value v_netwr.
macro_check_value v_vproz.
macro_check_value v_menge.
macro_check_value lt_eket-eindt.
macro_check_value lt_ekko-bukrs.
macro_check_value v_knttp.
macro_check_value lt_ekkn-sakto.
macro_check_value lt_ekpo-mwskz.</b>
*output string
lt_ekko-lv_record_identifier2 = '120'.
lt_ekko-lv_org_id1 = '1744'.
CONCATENATE lt_ekko-lv_record_identifier2
lt_ekko-lv_org_id1
v_vrtkz
lt_ekko-ebeln
lt_ekko-lifnr
lt_ekko-name1
v_total
lt_ekko-aedat
lt_ekko-zsrm_pcnum
lt_ekpo-afnam
lt_ekpo-txz01
v_netwr
v_vproz
v_menge
lt_eket-eindt
lt_ekko-bukrs
v_knttp
lt_ekkn-sakto
lt_ekpo-mwskz
INTO output_string3
SEPARATED BY c_tab.
IF v_vrtkz = 'M'.
LOOP AT lt_ekkn WHERE ebeln = lt_ekpo-ebeln
AND ebelp = lt_ekpo-ebelp.
MOVE: lt_ekkn-vproz TO v_vproz.
CASE lt_ekpo-knttp.
WHEN 'K'.
MOVE lt_ekkn-kostl TO v_knttp.
WHEN 'P'.
MOVE lt_ekkn-ps_psp_pnr TO v_knttp.
WHEN 'O'.
MOVE lt_ekkn-aufnr TO v_knttp.
WHEN OTHERS.
MOVE lt_ekpo-knttp TO v_knttp.
ENDCASE.
SHIFT v_vproz LEFT DELETING LEADING space.
CONCATENATE lt_ekko-lv_record_identifier2
lt_ekko-lv_org_id1
v_vrtkz
lt_ekko-ebeln
lt_ekko-lifnr
lt_ekko-name1
v_total
lt_ekko-aedat
lt_ekko-zsrm_pcnum
lt_ekpo-afnam
lt_ekpo-txz01
v_netwr
v_vproz
v_menge
lt_eket-eindt
lt_ekko-bukrs
v_knttp
lt_ekkn-sakto
lt_ekpo-mwskz
INTO output_string6
SEPARATED BY c_tab.
<b>TRANSLATE output_string6 USING '% '.</b>
WRITE 😕 output_string6.
ENDLOOP.
ELSE.
<b>TRANSLATE output_string3 USING '% '.</b>
WRITE 😕 output_string3.
ENDIF.
ENDLOOP.
ENDLOOP.
*concatenate for Organization Footer Record
CONCATENATE lv_record_identifier3
lv_org_id2
lv_org_name1
lv_detail_record_count
INTO output_string4
SEPARATED BY c_tab.
WRITE 😕 output_string4.
*concatenate for File Footer Record
CONCATENATE lv_record_identifier4
lv_extract_record_count
lv_file_record_count
INTO output_string5
SEPARATED BY c_tab.
WRITE 😕 output_string5.
Message was edited by: vj bb
‎2006 Jun 29 10:42 AM
Hi!
First some minor remark: if you are in a newer release, use a class to define the 'tab':
class cl_abap_char_utilities definition load.
data: l_field_seperator.
l_field_seperator = cl_abap_char_utilities=>horizontal_tab.Then you have a char1 field with the tabulator.
But looking at your code: why do you concatenate at all? You make an effort to assign % to empty fields, later you convert them back to space...
I would use a fixed structure. If you would like to have separators, I would include as every second field a sep01, sep02, sep03... which will be filled with '|', ' ', or the tabulator (just as you like).
Then you have a fixed field width - if you prefer to have shrinked display, just move this structure into a char255 field and use statement condense -> separatores like '|' will remain, but empty texts like ekpo-txz01 will be smaller.
In newer releases (700?) the concatenate has an option 'respecting blanks' -> you don't need the macros any longer, even if you stay with the concatenate version.
Regards,
Christian