Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

I need to fetch lifnr data from bseg and i should show in STCD3 as GST IN COLUMN

akon
Explorer
0 Kudos
613

I need to fetch lifnr data from bseg and link lfa1-lifnr and show the STCD3 as GST IN COLUMN

i have some condition

1. if the lifnr row is empty i have taken the HKONT field and shown in vendor no

and i have linked lifnr to show the STCD3 .

2. while am using

READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_FINAL1-HKONT.

sy-subrc = 4 error is comming

LOOP AT IT_BSEG INTO WA_BSEG .

WA_FINAL1-BELNR = WA_BSEG-BELNR.
WA_FINAL1-GJAHR = WA_BSEG-GJAHR.
WA_FINAL1-MWSKZ = WA_BSEG-MWSKZ.
WA_FINAL1-WRBTR = WA_BSEG-WRBTR.

IF WA_BSEG-TCODE NE 'MIRO' .

WA_FINAL1-LIFNR = WA_BSEG-LIFNR.

IF WA_BSEG-LIFNR = ' ' .
WA_FINAL1-LIFNR = WA_BSEG-HKONT. "WA_BSEG-HKONT.
ELSEIF
WA_FINAL1-LIFNR = WA_BSEG-LIFNR.
ENDIF.

ELSEIF WA_BSEG-TCODE NE 'FV60'.

WA_FINAL1-LIFNR = WA_BSEG-LIFNR.

IF WA_BSEG-LIFNR = ' '.

WA_FINAL1-LIFNR = WA_BSEG-HKONT.

ELSEIF
WA_FINAL1-LIFNR = WA_BSEG-LIFNR.
ENDIF.

ENDIF.

WA_FINAL1-MATNR = WA_BSEG-MATNR.
WA_FINAL1-WERKS = WA_BSEG-WERKS.
WA_FINAL1-MENGE = WA_BSEG-MENGE.
WA_FINAL1-MEINS = WA_BSEG-MEINS.
WA_FINAL1-EBELN = WA_BSEG-EBELN.
WA_FINAL1-EBELP = WA_BSEG-EBELP.
WA_FINAL1-HSN_SAC = WA_BSEG-HSN_SAC.
WA_FINAL1-BUKRS = WA_BSEG-BUKRS.

IF WA_BSEG-BSCHL EQ '89'.
WA_FINAL1-SEG_HKONT = WA_BSEG-HKONT.
ENDIF.

READ TABLE IT_BKPF INTO WA_BKPF WITH KEY BELNR = WA_BSEG-BELNR
GJAHR = WA_BSEG-GJAHR BINARY SEARCH.
IF WA_FINAL1-MWSKZ = 'R*'.
WA_FINAL1-TAX_DEC = 'RCM '.
ELSEIF WA_FINAL1-MWSKZ NE 'R*' .
WA_FINAL1-TAX_DEC = 'TAXABLE – GST'.
ENDIF.

IF SY-SUBRC = 0.
WA_FINAL1-BELNR = WA_BKPF-BELNR.
WA_FINAL1-GJAHR = WA_BKPF-GJAHR.
WA_FINAL1-BLDAT = WA_BKPF-BLDAT.
WA_FINAL1-BUDAT = WA_BKPF-BUDAT.
WA_FINAL1-TCODE = WA_BKPF-TCODE.
WA_FINAL1-XBLNR = WA_BKPF-XBLNR.
WA_FINAL1-WAERS = WA_BKPF-WAERS.
WA_FINAL1-KURSF = WA_BKPF-KURSF.
WA_FINAL1-AWKEY = WA_BKPF-AWKEY.

CALL FUNCTION 'ISP_GET_MONTH_NAME'
EXPORTING
DATE = WA_FINAL1-BLDAT
LANGUAGE = SY-LANGU
* MONTH_NUMBER = '00'
IMPORTING
* LANGU_BACK =
LONGTEXT = WA_FINAL1-MONTHS
* SHORTTEXT =
EXCEPTIONS
CALENDAR_ID = 1
DATE_ERROR = 2
NOT_FOUND = 3
WRONG_INPUT = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

ENDIF.

IF WA_FINAL1-TCODE EQ 'MIRO' .
CALL FUNCTION 'TEXT_SPLIT'
EXPORTING
LENGTH = 10
TEXT = WA_FINAL1-AWKEY
" AS_CHARACTER =
IMPORTING
LINE = WA_FINAL1-DOCNO
REST = WA_FINAL1-DOCYR.
ELSE.
WA_FINAL1-DOCNO = WA_FINAL1-BELNR.
ENDIF.


READ TABLE IT_EKKO INTO WA_EKKO WITH KEY EBELN = WA_BSEG-EBELN . "BINARY SEARCH.

IF WA_FINAL1-TCODE EQ 'MIRO' .

IF SY-SUBRC = 0.

WA_FINAL1-BSART = WA_EKKO-BSART.

IF WA_EKKO-BSART EQ 'ZVR' .
WA_FINAL1-PUR_RET = 'Return'.

ELSE. " WA_EKKO-BSART NE 'ZVR '.
WA_FINAL1-PUR_RET = 'Purchase'.
ENDIF.
ENDIF.

ENDIF.


READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_FINAL1-MATNR .
IF SY-SUBRC = 0.
WA_FINAL1-MAKTX = WA_MAKT-MAKTX.
ENDIF.

READ TABLE IT_MARC INTO WA_MARC WITH KEY MATNR = WA_BSEG-MATNR
WERKS = WA_BSEG-WERKS BINARY SEARCH.

IF SY-SUBRC = 0.
WA_FINAL1-STEUC = WA_MARC-STEUC.
ENDIF.

READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_FINAL1-LIFNR .

IF SY-SUBRC = 0 .

WA_FINAL1-NAME1 = WA_LFA1-NAME1.
WA_FINAL1-REGIO = WA_LFA1-REGIO.
WA_FINAL1-STCD3 = WA_LFA1-STCD3.

ENDIF.

READ TABLE IT_LFA1 INTO WA_LFA1 WITH KEY LIFNR = WA_FINAL1-HKONT.

IF SY-SUBRC = 0 .

WA_FINAL1-NAME1 = WA_LFA1-NAME1.
WA_FINAL1-REGIO = WA_LFA1-REGIO.
WA_FINAL1-STCD3 = WA_LFA1-STCD3.

ENDIF.


READ TABLE IT_SKAT INTO WA_SKAT WITH KEY SAKNR = WA_BSEG-HKONT .



IF WA_FINAL1-NAME1 = ''.
WA_FINAL1-SAKNR = WA_SKAT-SAKNR.
WA_FINAL1-NAME1 = WA_SKAT-TXT20.
ENDIF.
IF SY-SUBRC = 0."WA_LFA1-NAME1 = ''.
WA_FINAL1-SAKNR = WA_SKAT-SAKNR.
WA_FINAL1-TXT20 = WA_SKAT-TXT20.
ENDIF.

READ TABLE IT_T007S INTO WA_T007S WITH KEY MWSKZ = WA_FINAL1-MWSKZ . "BINARY SEARCH.

IF SY-SUBRC = 0.
WA_FINAL1-TEXT1 = WA_T007S-TEXT1.
ENDIF.

READ TABLE IT_T001W INTO WA_T001W WITH KEY WERKS = WA_BSEG-WERKS BINARY SEARCH.

IF SY-SUBRC = 0.
WA_FINAL1-T00_REGIO = WA_T001W-REGIO.
ENDIF.
LOOP AT IT_BSET INTO WA_BSET WHERE BUKRS = WA_BSEG-BUKRS AND
BELNR = WA_BSEG-BELNR AND
GJAHR = WA_BSEG-GJAHR.
IF WA_BSET-KSCHL = 'JIIG'.
WA_FINAL1-VAL_IGST = WA_BSET-FWSTE .
WA_FINAL1-PER_IGST = WA_BSET-KBETR / 10 .
ENDIF.
IF WA_BSET-KSCHL = 'JICG'.
WA_FINAL1-VAL_CGST = WA_BSET-FWSTE .
WA_FINAL1-PER_CGST = WA_BSET-KBETR / 10 .
ENDIF.
IF WA_BSET-KSCHL = 'JISG'.
WA_FINAL1-VAL_SGST = WA_BSET-FWSTE .
WA_FINAL1-PER_SGST = WA_BSET-KBETR / 10 .
ENDIF.

IF WA_FINAL1-VAL_IGST NE 0 .
WA_FINAL1-GST_RET = 'IGST' .
ENDIF.
IF WA_FINAL1-VAL_IGST = 0.
WA_FINAL1-GST_RET = 'GST' .
ENDIF.

* IF WA_FINAL1-VAL_IGST NE '0' .
* WA_FINAL1-GST_RET = 'IGST' .
* ENDIF.
* IF WA_FINAL1-VAL_CGST NE '0'.
* WA_FINAL1-GST_RET = 'GST' .
* ENDIF.

ENDLOOP.

WA_FINAL1-VAL_TOTAL = WA_FINAL1-VAL_IGST + WA_FINAL1-VAL_CGST + WA_FINAL1-VAL_SGST .
WA_FINAL1-TOT_GST = WA_FINAL1-PER_IGST + WA_FINAL1-PER_CGST + WA_FINAL1-PER_SGST .
WA_FINAL1-HWBAS = WA_BSET-HWBAS.

SHIFT WA_FINAL1-MATNR LEFT DELETING LEADING '0' .

APPEND WA_FINAL1 TO IT_FINAL1.
CLEAR WA_FINAL1.

ENDLOOP.

2 REPLIES 2

SimoneMilesi
Active Contributor
0 Kudos
443

Hello,
Please, share only the relevant slice of code and format it with copy->paste as text->button "code": it will make it easier for everyone to read it.

I do not see the issue with your task, to be honest:

  • read lfa1 into hashed table with just LIFNR and STCD3
  • Read into table BSEG
  • Loop BSEG
  • IF BSEG-LIFNR is not initial, use it to read internal table LFA1
  • ELSE use HKONT

This can be achieved in a more fancy way with new ABAP syntax but the logic is the same.
I'm assuming you are filtering all the relevant cases from BSEG so you always have LIFNR or HKONT with LIFNR value

thanga_prakash
Active Contributor
0 Kudos
443

prabhu duraikannu I hope your declaration of below fields are of same data type, as they all have conversion routines maintained try to declare it with their relevant types. In case if you have not maintained their respective data type then it could be the reason

WA_BSEG-HKONT TYPE HKONT
WA_BSEG-LIFNR TYPE LIFNR
WA_FINAL1-LIFNR TYPE LIFNR
WA_FINAL1-HKONT TYPE HKONT