Application Development and Automation 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: 
Read only

concatenate in loop..!!!

former_member622718
Participant
0 Likes
5,465
hi i wanto to display amount in + - value in in amount ..!! how to do.







LOOP AT l_bseg INTO DATA(w_bseg).

    IF W_BSEG-shkzs = 'H'.
      CONCATENATE '-'  and 'WRBTR' INTO lv_var SEPARATED BY space.
    ENDIF.
    IF W_BSEG-shkzs = 'S'.
      CONCATENATE '+'  and 'WRBTR' INTO lv_var SEPARATED BY space.
    ENDIF.


    gwa_final-belnr = w_bseg-belnr.
*      gwa_final-gjahr = w_bseg-gjahr.
    gwa_final-augcp = w_bseg-augcp.
    gwa_final-shkzg = w_bseg-shkzg.

    gwa_final-gsber = w_bseg-gsber.
    gwa_final-wrbtr = w_bseg-wrbtr.
    gwa_final-pswsl = w_bseg-pswsl.
    gwa_final-dzuonr = w_bseg-zuonr.
    gwa_final-sgtxt = w_bseg-sgtxt.
    gwa_final-hkont = w_bseg-hkont.
    gwa_final-lifnr = w_bseg-lifnr.
    gwa_final-prctr = w_bseg-prctr.
    gwa_final-bupla = w_bseg-bupla.
    gwa_final-budat = w_bseg-h_budat.
    gwa_final-bldat = w_bseg-h_bldat.

    READ TABLE l_bkpf INTO DATA(w_bkpf) WITH KEY belnr = w_bseg-belnr BINARY SEARCH.

    IF sy-subrc EQ 0.
      gwa_final-cpudt = w_bkpf-cpudt.
      gwa_final-xblnr = w_bkpf-xblnr.
      gwa_final-bktxt = w_bkpf-bktxt.

    ENDIF.

    LOOP AT l_skat INTO DATA(w_skat) WHERE saknr = w_bseg-hkont.
* READ TABLE l_skat INTO DATA(w_skat) WITH KEY saknr = w_bseg-hkont BINARY SEARCH.

      IF sy-subrc EQ 0.
        gwa_final-saknr = w_skat-saknr.
        gwa_final-txt50 = w_skat-txt50.
      ENDIF.
    ENDLOOP.


    READ TABLE l_lfa1 INTO DATA(w_lfa1) WITH KEY lifnr = w_bseg-lifnr .

    IF sy-subrc EQ 0.
      gwa_final-name1 = w_lfa1-name1.
    ENDIF.

    APPEND gwa_final TO gt_final.
    CLEAR gwa_final.
  ENDLOOP.
1 ACCEPTED SOLUTION
Read only

michael_piesche
Active Contributor
5,150

You are probably looking for a solution like the following:

CASE W_BSEG-shkzs.
  WHEN 'H'.
    gwa_final-wrbtr = w_bseg-wrbtr * -1.
  WHEN 'S'.
    gwa_final-wrbtr = w_bseg-wrbtr.
ENDCASE.

Currently, with the concatenation statement, you are only concatenating the literals '-' and 'WRBTR' into the variable lv_var. Also, concatenation should be used on character variables, and is not possible with number values.

CONCATENATE '-' and 'WRBTR' INTO lv_var SEPARATED BY space

You are probably looking for a solution like the following:

CASE W_BSEG-shkzs.
  WHEN 'H'.
    gwa_final-wrbtr = w_bseg-wrbtr * -1.
  WHEN 'S'.
    gwa_final-wrbtr = w_bseg-wrbtr.
ENDCASE.

Currently, with the concatenation statement, you are only concatenating the literals '-' and 'WRBTR' into the variable lv_var. Also, concatenation should be used on character variables, and is not possible with number values.

CONCATENATE '-' and 'WRBTR' INTO lv_var SEPARATED BY space
8 REPLIES 8
Read only

michael_piesche
Active Contributor
5,151

You are probably looking for a solution like the following:

CASE W_BSEG-shkzs.
  WHEN 'H'.
    gwa_final-wrbtr = w_bseg-wrbtr * -1.
  WHEN 'S'.
    gwa_final-wrbtr = w_bseg-wrbtr.
ENDCASE.

Currently, with the concatenation statement, you are only concatenating the literals '-' and 'WRBTR' into the variable lv_var. Also, concatenation should be used on character variables, and is not possible with number values.

CONCATENATE '-' and 'WRBTR' INTO lv_var SEPARATED BY space
Read only

0 Likes
5,150

hi sir,

can i use this in main loop ???

Read only

0 Likes
5,150

Sir, but still not working..! I did as u told...!!!

Read only

0 Likes
5,150

Manoj Kumar, please give more information about your error and what is not working. Is there a ST22 dump or do you have a working application that displays faulty information? Show relevant coding and screenshots to support your problems.

Read only

5,150

Hi manoj16393,

you should do what people advise to you.

You need to replace

    IF W_BSEG-shkzs = 'H'.
      CONCATENATE '-'  and 'WRBTR' INTO lv_var SEPARATED BY space.
    ENDIF.
    IF W_BSEG-shkzs = 'S'.
      CONCATENATE '+'  and 'WRBTR' INTO lv_var SEPARATED BY space.
    ENDIF.

by

CASE W_BSEG-shkzs.
  WHEN 'H'.
    gwa_final-wrbtr = w_bseg-wrbtr * -1.
  WHEN 'S'.
    gwa_final-wrbtr = w_bseg-wrbtr.
ENDCASE.

as michael.piesche already told. If you replace like this, the value will be correct.

In one of your previous Questions I corrected one Code of you, where you use BSEG and BKPF tables, but you are still not using keyfields (BUKRS, BELNR, GJAHR) of the tables BSEG and BKPF. For SKAT table it's also important to use the keyfields (SPRAS, KTOPL, SAKNR). If you don't use the keyfields your output will be always wrong.

Greetings
Stephan

Read only

venkateswaran_k
Active Contributor
5,150

Hi

Not able to get your requirement?

Why you want to concatinate?

Why dont you multiply with -1 if Credit.

Please eloborate your requirement

Read only

former_member622718
Participant
0 Likes
5,150

HI I WANT TO DISPLAY BSEG FIELD WRBTR IN + OR - VALUR IN ALV OUTPUT ..!

Read only

former_member622718
Participant
0 Likes
5,150

Thank you Michael Piesche and Stephan Köster.. i am getting values