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

If statement is not working

Former Member
0 Likes
2,314

Hello Experts,


I am facing issue with date is initial.


Actually I am trying to do transfer posting using IDOCs. If the posting date is initial then I am trying to assign system date is default but my 'if condition is not working'

   

      lw_seg_head = IDOC_DATA-sdata.

      MOVE-CORRESPONDING lw_seg_head to lw_gm_head.

      if lw_gm_head-PSTNG_DATE is INITIAL.

         lw_gm_head-PSTNG_DATE = sy-datum.

      endif.


Please advise.

Hello Experts,


I am facing issue with date is initial.


Actually I am trying to do transfer posting using IDOCs. If the posting date is initial then I am trying to assign system date is default but my 'if condition is not working'

   

      lw_seg_head = IDOC_DATA-sdata.

      MOVE-CORRESPONDING lw_seg_head to lw_gm_head.

      if lw_gm_head-PSTNG_DATE is INITIAL.

         lw_gm_head-PSTNG_DATE = sy-datum.

      endif.


Please advise.

6 REPLIES 6
Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,311

Hi Vada,

What is the date type of field lw_gm_head-PSTNG_DATE.


Is it declared as type sy-datum or char. Declare it as sy-datum If it is not declared .


Thanks

-Learner

Read only

rahul_mahajan
Active Participant
0 Likes
1,311

Hello,

Did you tried searching SCN before posting this question? I would suggest to read first.

To answer your question, please refer below SCN threads. There could be many other threads on same topics.

https://scn.sap.com/thread/950883

Hope this helps and let us know if this is not something you were looking for.

Thanks,

Rahul

Read only

former_member184158
Active Contributor
0 Likes
1,311

Hi,

try to define the PSTNG_DATE as sy-datum or sdate.

if lw_gm_head-PSTNG_DATE is INITIAL

or  lw_gm_head-PSTNG_DATE = '00000000'.

        lw_gm_head-PSTNG_DATE = sy-datum.

      endif.



Regerads

Ibr

Read only

Former Member
0 Likes
1,311

Hi,

If you declared posting date as type sy-datum,Then use below condition.

       lw_seg_head = IDOC_DATA-sdata.

      MOVE-CORRESPONDING lw_seg_head to lw_gm_head.

      if lw_gm_head-PSTNG_DATE = '00000000'.

         lw_gm_head-PSTNG_DATE = sy-datum.

      endif.

Hope this will help you.

Thanks

KH

Read only

Private_Member_7726
Active Contributor
0 Likes
1,311

Hi,

That to me indicates - you have assigned to lw_gm_head-PSTNG_DATE a value that is not initial (SPACE for example). If the field type is 'date' then the initial value for that type is '00000000'.

If you want to do programming, you should really be able to solve this kind of problems on your own...

cheers

Jānis

Read only

former_member246634
Active Participant
0 Likes
1,311

Hi!

Since date field is never empty, it contains only zeros. You can use:

lw_seg_head = IDOC_DATA-sdata.

MOVE-CORRESPONDING lw_seg_head to lw_gm_head.

if lw_gm_head-PSTNG_DATE EQ '00000000'.

     lw_gm_head-PSTNG_DATE = sy-datum.

endif.


or


lw_seg_head = IDOC_DATA-sdata.

MOVE-CORRESPONDING lw_seg_head to lw_gm_head.

if lw_gm_head-PSTNG_DATE CO '0'. "Contains only zeros

     lw_gm_head-PSTNG_DATE = sy-datum.

endif.


Greetings

Bartłomiej