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: 

line items repeating in PO texts

Hamza_imran
Participant
0 Kudos

Hi gurus,

I've made an adobe form and i've written this code for item text and scope of work for our PO but it is concatinating the line items of all the texts into a single field. below is the code and the Output that is generating. What i want is that line item text of one material shouldn't repeat in the next material. Any help regarding this would be highly appreciated.

LOOP AT item INTO wa_item WHERE loekz IS INITIAL.

data: i type num value 1,
      k TYPE num value 10,
      num TYPE num.


concatenate 'Service #' i+1 into lv_service SEPARATED BY space.

**For Scope of Work
data   : lv_name1 TYPE THEAD-TDNAME.
move HEADER-EBELN to lv_name1.
 num = num + k.
*num = num + i.

CONCATENATE  lv_name1 '000' num INTO lv_name1.
CLEAR: tline.

CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    ID                            = 'F01'
    LANGUAGE                      = 'E'
    NAME                          =  lv_name1
    OBJECT                        = 'EKPO'
  TABLES
    LINES                         = TLINE
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8
          .
IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE lv_sow  TLINE-TDLINE INTO lv_sow  SEPARATED BY lf.
ENDLOOP.
CONDENSE lv_sow .

SHIFT lv_sow  LEFT DELETING LEADING LF.

ENDIF.
*move num to wa_item-msr_item.
*modify item from wa_item.

"For Item Desceiption
CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    ID                            = 'F03'
    LANGUAGE                      = 'E'
    NAME                          = lv_name1
    OBJECT                        = 'EKPO'
  TABLES
    LINES                         = TLINE
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8
          .
IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE lv_des  TLINE-TDLINE INTO lv_des   SEPARATED BY LF.
ENDLOOP.
CONDENSE lv_des  .

SHIFT lv_des  LEFT DELETING LEADING LF.
ENDIF.

CLEAR: TLINE.

endloop.

Regards,

Hamza.

20 REPLIES 20

abo
Active Contributor
0 Kudos

TLINE is a table: use REFRESH instead of CLEAR

Also, move the initialization out of the loop: it's not the text from the first item spilling over to the next item, it really is reading the same text over and over.

mateuszadamus
Active Contributor

Better yet, as REFRESH is obsolete, use CLEAR itab[] (with square brackets). This will ensure that the lines of the table are cleared (removed) and not the header.


Kind regards,
Mateusz

0 Kudos

tried using REFRESH and CLEAR itab[], still the problem persists.

mateuszadamus
Active Contributor
0 Kudos

Hello humza_immi

Use CLEAR itab[] (with square brackets) to clear (remove) the lines of the internal table.

Put additional CLEAR itab[] between READ_TEXT function calls, unless you want to have text from both READ_TEXT in the output.

Clear the LV_DES and LV_SOW variables.

You can also define the NUM variable as EBELP and you won't have to concatenate zero before the number (will be added automatically).

Kind regards,
Mateusz

0 Kudos

Use CLEAR itab[] (with square brackets) to clear (remove) the lines of the internal table. done

Put additional CLEAR itab[] between READ_TEXT function calls, unless you want to have text from both READ_TEXT in the output. i need both the texts

Clear the LV_DES and LV_SOW variables. when doing this it's not showing any data. where exactly should i use this?

You can also define the NUM variable as EBELP and you won't have to concatenate zero before the number (will be added automatically). done

0 Kudos

As I understand LV_DES and LV_SOW should be initialized before showing each of the PO item lines.

Where exactly do you execute the LOOP you showed in your question?

Where are the LV_DES and LV_SOW variables used?

Kind regards,
Mateusz

0 Kudos

this is my whole code which i've coded in the code initialization in my adobe form. Also i've initialized these two variables in the context area of my interface. The field lv_des is used in the red area marked in my attached ss in the question. The other field lv_sow is the field with 'item1 text' and 'item 2 text'

DATA: lv_object TYPE thead-tdname,
      tline     TYPE tline OCCURS 0 WITH HEADER LINE,
      lv_n      TYPE num,
      ebelp     TYPE num,
      i_ftaxp   TYPE ftaxp OCCURS 0 WITH HEADER LINE.
DATA: lf TYPE c LENGTH 1.
      lf =  |\n|.
lv_n = 10.

break hamza_abap.

SELECT SINGLE banfn INTO pr FROM ekpo WHERE ebeln EQ header-ebeln.
SELECT SINGLE zpqcsn zcode zterm INTO ( pqcs, lv_code, lv_zterm ) FROM ekko WHERE ebeln EQ header-ebeln.
SELECT SINGLE address city telf INTO ( lv_delivery, lv_city, lv_telf ) FROM zaj_address WHERE code EQ lv_code.
SELECT SINGLE text1 INTO lv_paymentt FROM t052u WHERE zterm EQ lv_zterm AND spras EQ sy-langu.

  "Getting short text
"  select SINGLE ktext1 menge meins tbtwr into lv_description FROM esll WHERE packno eq lv_services.
 "   CONCATENATE lv_servicess to lv_description.


*----------------------------------------------------------------------------------------
*BOC BY H.NAEEM 09/16/2019
 SELECT SINGLE telf2 INTO lv_phone FROM lfa1 WHERE lifnr EQ header-lifnr.         "Getting  Phone No
 SELECT SINGLE telf1 INTO lv_tel FROM lfa1 WHERE lifnr EQ header-lifnr.         "Getting  Telp No
 SELECT SINGLE adrnr INTO @DATA(lv_addr) FROM lfa1 WHERE lifnr EQ @header-lifnr.
 SELECT SINGLE smtp_addr INTO lv_email FROM adr6 WHERE addrnumber EQ lv_addr.      "Getting  Email Address


CONCATENATE lv_phone ',' lv_tel INTO LV_PHONE_TEL SEPARATED BY space .
*BREAK naeem_abap.
*---------------------------------------------------------------------  -----------------------
*EOC BY H.NAEEM 09/16/2019

  CONCATENATE lv_delivery  lv_city lv_telf INTO lv_delivery SEPARATED BY lf.

data   : lv_name TYPE THEAD-TDNAME.
move header-EBELN to lv_name.

*For Special Instructions
CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    ID                            = 'F01'
    LANGUAGE                      = 'E'
    NAME                          =  lv_name
    OBJECT                        = 'EKKO'
  TABLES
    LINES                         = TLINE
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8
          .
IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE LV_SPE_INS TLINE-TDLINE INTO LV_SPE_INS SEPARATED BY lf.
ENDLOOP.
CONDENSE LV_SPE_INS.

SHIFT LV_SPE_INS LEFT DELETING LEADING LF.
ENDIF.



LOOP AT item INTO wa_item WHERE loekz IS INITIAL.
data: i type num value 1,
      k TYPE num value 10,
      num TYPE num.

**For Scope of Work
data   : lv_name1 TYPE THEAD-TDNAME.
move HEADER-EBELN to lv_name1.
 num = num + k.
 CONCATENATE  lv_name1 '000' num INTO lv_name1.
clear tline[] .

CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    ID                            = 'F01'
    LANGUAGE                      = 'E'
    NAME                          =  lv_name1
    OBJECT                        = 'EKPO'
  TABLES
    LINES                         = TLINE
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8
          .
IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE lv_sow  TLINE-TDLINE INTO lv_sow  SEPARATED BY lf.
ENDLOOP.
CONDENSE lv_sow .

SHIFT lv_sow  LEFT DELETING LEADING LF.


ENDIF.


*move num to wa_item-msr_item.
*modify item from wa_item.

"For Item Desceiption
CALL FUNCTION 'READ_TEXT'
  EXPORTING
*   CLIENT                        = SY-MANDT
    ID                            = 'F03'
    LANGUAGE                      = 'E'
    NAME                          = lv_name1
    OBJECT                        = 'EKPO'
  TABLES
    LINES                         = TLINE
 EXCEPTIONS
   ID                            = 1
   LANGUAGE                      = 2
   NAME                          = 3
   NOT_FOUND                     = 4
   OBJECT                        = 5
   REFERENCE_CHECK               = 6
   WRONG_ACCESS_TO_ARCHIVE       = 7
   OTHERS                        = 8
          .
IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE lv_des  TLINE-TDLINE INTO lv_des   SEPARATED BY LF.
ENDLOOP.
CONDENSE lv_des  .

SHIFT lv_des  LEFT DELETING LEADING LF.
ENDIF.

clear tline[] .

endloop.

*if wa_item-ZSOW is initial.
*      MOVE '' TO wa_item-flag.
*else.
*  move 'X' TO wa_item-flag.
*  endif.
"FETTING DOCUMNET NO Hamza
SELECT SINGLE knumv FROM ekko INTO @DATA(lv_doc_con) WHERE ebeln = @header-ebeln.

*SELECT SINGLE knumv FROM ekko INTO @DATA(lv_doc_con) WHERE ebeln = @header-ebeln.
*---------------------------------------------------------------------------------

LOOP AT item INTO wa_item WHERE loekz IS INITIAL.

*  BOC by Hamza 09/10/2020
  ""Getting service no
  SELECT SINGLE packno  INTO @DATA(lv_service) FROM eslh WHERE packno eq @wa_item-packno.
  select SINGLE sub_packno INTO @DATA(lv_services) FROM esll where packno eq @wa_item-packno.
   SELECT SINGLE srvpos INTO lv_description FROM esll where packno eq lv_services.

   "Adding line item Quantity and UOM
   SELECT SINGLE menge INTO @DATA(lv_menge) FROM esll where packno eq @lv_services.
   SELECT SINGLE meins INTO @DATA(lv_meins) from esll where packno eq @lv_services.
SHIFT lv_description LEFT DELETING LEADING '0'.
*----------BOC BY Hamza /04/08/2020----------------------
    "Get Discount [ZST3]
  SELECT SINGLE  kbetr FROM prcd_elements INTO LV_DISCOUNT
         WHERE knumv EQ lv_doc_con AND kschl EQ 'ZST3' .

"Fething Discount Type
  SELECT SINGLE kbetr from PRCD_ELEMENTS INTO lv_dscnt WHERE kschl eq 'ZST3'.
*-------------------- EOC BY Hamza -------------------

WA_ITEM-EBELP = SY-TABIX.   "SR NO.


r_plant = wa_item-werks.
SELECT SINGLE name1 INTO plant FROM t001w WHERE werks EQ r_plant.
*  MOVE WA_ITEM-EBELP TO EBELP.
*
*  EBELP = EBELP * LV_N.
*
"LOC BY H.NAEEM FOR UNIT PRICE
 wa_item-netpr = wa_item-brtwr / wa_item-menge.
 wa_item-NTPR = wa_item-brtwr / wa_item-menge.
*  wa_item-CNFM_QTY = wa_item-brtwr / wa_item-menge.
*    wa_item-GNETWR = wa_item-brtwr / wa_item-menge.



BREAK FIORI_ADMIN.

"-----Tax Calculation-----"
IF wa_item-mwskz EQ 'I7'.
wa_item-kbetr = wa_item-kbetr + 17.
ELSEIF wa_item-mwskz EQ 'I6'.
wa_item-kbetr = wa_item-kbetr + 16.
ELSEIF wa_item-mwskz EQ 'I3'.
wa_item-kbetr = wa_item-kbetr + 13.
ELSEIF wa_item-mwskz EQ 'VZ'.
wa_item-kbetr = wa_item-kbetr + 0.
ELSEIF wa_item-mwskz EQ 'I9'.
wa_item-kbetr = wa_item-kbetr + 10.
ENDIF.

"-----GST Amount Calculation-----"
IF WA_ITEM-KSCHL EQ 'ZSTV' AND wa_item-mwskz EQ 'VZ'.   "Sugar Scenario
wa_item-kwert = wa_item-menge * ( wa_item-kbetr ).
ELSEIF WA_ITEM-KSCHL EQ 'ZSTV' AND wa_item-mwskz EQ 'I7'.   "Sugar Scenario
wa_item-kwert = wa_item-brtwr * ( wa_item-kbetr / 100 ).
  ELSE.
wa_item-kwert = wa_item-brtwr * ( wa_item-kbetr / 100 ).
ENDIF.
"----Total Amount-----"

wa_item-netwr = wa_item-kwert + wa_item-brtwr.
MODIFY item FROM wa_item.





"----Grand Total----"
lv_tvalue = wa_item-brtwr + lv_tvalue.
lv_tgst = lv_tgst + wa_item-kwert.
lv_tamount = lv_tamount + wa_item-netwr.

*---------------------------------------------
*"BOC BY H.NAEEM
DATA   lv_amount_st  TYPE spell.

CALL FUNCTION 'SPELL_AMOUNT'
EXPORTING
  amount    = lv_tamount
  currency  = 'PKR'
*      FILLER    = ''
  language  = sy-langu
IMPORTING
  in_words  = lv_amount_st
EXCEPTIONS
  not_found = 1
  too_large = 2
  OTHERS    = 3.

IF sy-subrc EQ 0 .
  lv_amount = lv_amount_st-word.
  CONCATENATE 'Amount in Words :' lv_amount 'ONLY' INTO lv_amount SEPARATED BY space.
  ENDIF.

**------------------
*"Created By
**-------------------
 SELECT SINGLE ernam  FROM ekko INTO @DATA(lv_ernam) WHERE ebeln = @header-ebeln .
 SELECT SINGLE persnumber FROM usr21 INTO @DATA(lv_persn) WHERE bname EQ @lv_ernam.
 SELECT SINGLE name_text  FROM adrp  INTO prepared_by  WHERE persnumber EQ lv_persn.
 CONCATENATE '(' prepared_by ')' INTO prepared_by SEPARATED BY space.



 SELECT  SINGLE ekgrp INTO @DATA(lv_pgrp) FROM eban WHERE banfn EQ @pr.
 SELECT SINGLE telfx   INTO @DATA(lv_pgrp_txtt) FROM t024 WHERE ekgrp EQ @lv_pgrp .
 CONCATENATE  pr '/' lv_pgrp_txtt INTO lv_pgrp_txt SEPARATED BY SPACE.

**-------------------------------------------------


*-------------------------------
move lv_menge to wa_item-menge .
move lv_meins to wa_item-meins .
*-------------------------------

modify item from wa_item.
CLEAR: wa_item.
ENDLOOP.

0 Kudos

sorry i've declared the fields lv_sow and lv_des in the global data in my interface.

0 Kudos

Okay, so here is your issue - in the INITIALIZATION event of the entire form you run a LOOP and gather text for each of the items. You gather these texts to a simple variable.

FORM INITIALIZATION
lv_des = lv_des + text_for_item_1
lv_des = lv_des + text_for_item_2
SHOW ITEM 1
PRINT lv_des " which contains text_for_item_1 and text_for_item_2
SHOW ITEM 2
PRINT lv_des " which contains text_for_item_1 and text_for_item_2

You either need to read the texts for each item separately or you need to store texts read in the INTIALIZATION of the form in an internal table and then show texts from this internal table, based on the PO item currently shown.

Kind regards,
Mateusz

0 Kudos

Dear Mateusz,

How can i read texts for each item separately?

or how can i store the texts in the initialization of the form?

Really sorry i'm new to this and have problem in understanding your answer.

Warm Regards.

0 Kudos

For example:

1. Define a global table variables of the same type as LV_DES and LV_SOW, e.g.: GT_DES and GT_SOW

2. In the item LOOP read the texts for each item, concatenate them into the LV_DES/LV_SOW and append LV_DES/LV_SOW into global tables GT_DES/GT_SOW.

3. In the INITIALIZE event of the text field in the item's grid read the text and assign it to the field's value. You can read it based on the current item count or based on the item number, but this require GT_DES/GT_SOW tables to have this stored.


Kind regards,
Mateusz

0 Kudos

Should i concatenate them in the same loop in which i posted the question in or use a separate loop for reading them?

Can you please give an example for the 3rd point?

0 Kudos

Yes, you can concatenate them in the same LOOP. It does not matter. The thing is, that you need to save them in an internal table (one text = one record of the table) and provide these internal tables to the Adobe Form.

Then, in the Adobe Form, in the INITIALIZATION event of the field you want the text to show (from you question I see it's in a table), you do something like shown below:

// take the text from the internal table importing parameter (called IT_DES, TEXT is a field in which the text is stored)
// could be done in one line, but for the sake of example
var lv_des_text_for_this_item = xfa.resolveNode("$record.it_des[" + this.index + "].text").value;
// assign the text to the value of the cell
this.rawValue = lv_des_text_for_this_item;

The code example might not work "out of the box", but I'm not able to test it now, so you will need to troubleshoot it on your own.

Kind regards,
Mateusz

0 Kudos

Dear mateuszadamus,

I tried to do as u say but I'm stuck here. Please advise what to do.

Now when i'm trying to append it's giving me the following error:

Please help me where am i going wrong.

0 Kudos

also making my internal table like this.

0 Kudos

Assuming GT_DES is a table which rows are like IT_DES, then you need to append whole IT_DES to GT_DES.

APPEND it_des TO gt_des.

Kind regards,
Mateusz

raymond_giuseppi
Active Contributor
0 Kudos

Where

  • Did you change value of lv_name1 to include item number
  • Did you clear the generated string lv_des and lv_sow

Remarks

  • CLEAR is okay as long as your internal table has no header line.
  • You should only add a line feed (LF) during concatenation if TDFORMAT is not initial (to respect original text formating)

0 Kudos
  • Did you change value of lv_name1 to include item number : Yes i did.
  • Did you clear the generated string lv_des and lv_sow : where exactly should i clear it as clearing these variables is vanishing the data of these two fields.

0 Kudos

Replace, for example

IF SY-SUBRC EQ 0.
LOOP AT TLINE WHERE TDLINE IS NOT INITIAL.
  CONCATENATE LV_SPE_INS TLINE-TDLINE INTO LV_SPE_INS SEPARATED BY lf.
ENDLOOP.
CONDENSE LV_SPE_INS.
SHIFT LV_SPE_INS LEFT DELETING LEADING LF.
ENDIF.

with

CLEAR LV_SPE_INS.
IF SY-SUBRC EQ 0.
  LOOP AT TLINE.
    IF TLINE-TDLINE IS INITIAL OR LV_SPE_INS IS INITIAL.
      CONCATENATE LV_SPE_INS TLINE-TDLINE INTO LV_SPE_INS SEPARATED BY space.
    ELSE.
      CONCATENATE LV_SPE_INS TLINE-TDLINE INTO LV_SPE_INS SEPARATED BY lf.
    ENDIF.
  ENDLOOP.
  CONDENSE LV_SPE_INS.
ENDIF.

0 Kudos

i did exactly this and it's not showing the data.